package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    //用户列表查询
    List<User> selectList(UserDto userDto);
    //批量删除用户
    void deleteByIds(List<Integer> ids);

    //添加用户
    @Insert("insert into user(username,name,password,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time) " +
            "values(#{username},#{name}, #{password},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void insert (User user);
    //根据ID查询
    @Select("select id, username, name, password, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user where id=#{id}")
  User selectByID(Integer id);
    //修改用户
    void upDate(User user);
    //查询所有用户
    @Select("select id, username, name, password, phone, email, gender, status, dept_id, role_id, image, remark, create_time ,update_time from user ")
    List<User> selectAllList();
    //根据角色查询用户
    List<User> roleList(String roleLabel);
    //根据部门查询用户
    List<User> deptList(Integer deptId);
    //根据用户名查询用户
    @Select("select u.*,r.label role_label from user u left join role r on u.role_id=r.id where username=#{username}")
    User selectByUsername(String username);
}
